import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_magic_planet/common/constant.dart';
import 'package:flutter_magic_planet/component/toast.dart';
import 'package:flutter_magic_planet/module/mine/widget/header.dart';
import 'package:get/get.dart';

import 'mine_logic.dart';

class MinePage extends StatefulWidget {
  @override
  _MinePageState createState() => _MinePageState();
}

class _MinePageState extends State<MinePage> {
  final MineLogic logic = Get.put(MineLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: AnnotatedRegion(
        value: SystemUiOverlayStyle.dark,
        child: Container(
          child: ListView(
            children: [
              Padding(
                padding: EdgeInsets.fromLTRB(
                    paddingHorizontal, 32, paddingHorizontal, 0),
                child: MineHeader(),
              ),
              SizedBox(height: 2),
              Padding(
                padding: EdgeInsets.symmetric(horizontal: paddingHorizontal),
                child: _buildMenus(),
              ),
              SizedBox(height: 12),
              Padding(
                padding: EdgeInsets.symmetric(horizontal: paddingHorizontal),
                child: _buildService(),
              ),
              // _buildList(),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<MineLogic>();
    super.dispose();
  }

  _buildMenu({required var title, required Widget icon, VoidCallback? onTap}) {
    return GestureDetector(
      child: Padding(
        child: Column(
          children: [
            icon,
            SizedBox(height: 4),
            Text(title),
          ],
        ),
        padding: EdgeInsets.symmetric(horizontal: 0, vertical: 16),
      ),
      onTap: onTap,
    );
  }

  _buildMenus() {
    return Card(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          _buildMenu(
              title: '离线缓存',
              icon: Icon(Icons.cloud_download_outlined, color: primaryColor),
              onTap: () {
                Toast.show('离线缓存');
              }),
          _buildMenu(
              title: '观看历史',
              icon: Icon(Icons.history_outlined, color: primaryColor),
              onTap: () {
                Toast.show('观看历史');
              }),
          _buildMenu(
              title: '我的收藏',
              icon: Icon(Icons.star_outline, color: primaryColor),
              onTap: () {
                Toast.show('我的收藏');
              }),
          _buildMenu(
            title: '会员中心',
            icon: Icon(Icons.account_balance_wallet_outlined,
                color: primaryColor),
            onTap: () {
              Toast.show('会员中心');
            },
          ),
        ],
      ),
    );
  }

  _buildService() {
    return Card(
      clipBehavior: Clip.antiAlias,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: EdgeInsets.symmetric(
                horizontal: paddingHorizontal, vertical: 12),
            child: Text(
              '更多服务',
              style: TextStyle(fontWeight: FontWeight.w600, fontSize: 16),
            ),
          ),
          Divider(height: 1),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              _buildMenu(
                title: '意见反馈',
                icon: Icon(Icons.feedback_outlined, color: primaryColor),
                onTap: () {
                  Toast.show('意见反馈');
                },
              ),
              _buildMenu(
                title: '检查更新',
                icon: Icon(Icons.upgrade_outlined, color: primaryColor),
                onTap: () {
                  Toast.show('检查更新');
                },
              ),
              _buildMenu(
                title: '清空缓存',
                icon: Icon(Icons.cached_outlined, color: primaryColor),
                onTap: () {
                  Toast.show('清空缓存');
                },
              ),
              _buildMenu(
                title: '设置',
                icon: Icon(Icons.app_settings_alt_rounded, color: primaryColor),
                onTap: () {
                  Toast.show('设置');
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}
